package org.aceor.mddal.atom.util;

import com.google.common.base.Strings;
import org.apache.commons.dbcp.BasicDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by lxue on 16/3/29.
 */
public class DsUtil {
    private static final Logger LOG = LoggerFactory.getLogger(DsUtil.class);

    public static boolean checkDbcpDsNecessaryParams(BasicDataSource dataSource) {
        if (null == dataSource) {
            return false;
        }
        if (Strings.isNullOrEmpty(dataSource.getUrl())) {
            LOG.error("DsUtil$checkDbcpDsNecessaryParams ==> {} is Empty!", "URL");
            return false;
        }
        if (Strings.isNullOrEmpty(dataSource.getPassword())) {
            LOG.error("DsUtil$checkDbcpDsNecessaryParams ==> {} is Empty!", "Password");
            return false;
        }
        if (Strings.isNullOrEmpty(dataSource.getUsername())) {
            LOG.error("DsUtil$checkDbcpDsNecessaryParams ==> {} is Empty!", "Username");
            return false;
        }
        if (Strings.isNullOrEmpty(dataSource.getDriverClassName())) {
            LOG.error("DsUtil$checkDbcpDsNecessaryParams ==> {} is Empty!", "DriverClassName");
            return false;
        }
        return true;
    }
}
